<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2018/6/4
 * Time: 17:27
 */
namespace App\Modules\Jobs\Services;
use App\Modules\User\Models\UserAverageRecommend;
use App\Modules\User\Models\UserRecommend;
use Redis;

class UpdateSelfRecoAverageService {

    /**
     * 自荐表被查看次数
     */
    public static function updateRecommendAllReadTimes(){
        $readTime = Redis::hget('average_recommend_info:', 'readTimes');

        if ($readTime) {
            $readTime++;
        }else{
            $readTime = UserAverageRecommend::RecommendAllReadTimes();
        }
        Redis::hset('average_recommend_info:', 'readTimes',$readTime);
        return $readTime;
    }

    /**
     * 用户自荐表数
     */
    public static function RecommendAllTimes(){
        $recommendTimes = Redis::hget('average_recommend_info:', 'recommendTimes');

        if ($recommendTimes ) {
            $recommendTimes++;
        }else{
            $recommendTimes = UserAverageRecommend::RecommendAllTimes();
        }
        Redis::hset('average_recommend_info:', 'recommendTimes',$recommendTimes);
        return $recommendTimes;
    }
    /**
     * 用户自荐成功次数
     */
    public static function RecommendAllSuccessTimes(){
        $RecommendSuccessTimes = Redis::hget('average_recommend_info:', 'recommendSuccessTimes');

        if ($RecommendSuccessTimes) {
            $RecommendSuccessTimes++;
        }else{
            $RecommendSuccessTimes = UserAverageRecommend::RecommendAllSuccessTimes();
        }
        Redis::hset('average_recommend_info:', 'recommendSuccessTimes',$RecommendSuccessTimes);

        return $RecommendSuccessTimes;
    }

    /**
     * 自荐用户数
     */
    public static function RecommendAllUserNum(){
        /*$RecommendSuccessTimes = Redis::hget('average_recommend_info:', 'recommendAllUserNum');

        if ($RecommendSuccessTimes ) {
            $RecommendSuccessTimes++;
        }else{*/
        $RecommendSuccessTimes = UserAverageRecommend::RecommendUserNum();
        //}
        Redis::hset('average_recommend_info:', 'recommendAllUserNum',$RecommendSuccessTimes);
        return $RecommendSuccessTimes;
    }

}